<template>
  <div class="newslist">
    <div class="news-line font-xbs"></div>
    <img src="/assets/imgs/arrow.png" class="news-arrow unselectable" alt="" style="height: 20px;" />
    <div class="card-section">
      <div class="card-row" v-for="(item, row) in  rownum " :key="item">
        <Newscard v-for="item2 in articleRowNum(row)" :key="item2"
          :article-id="user.pages.sub.list[((item) - 1) * 3 + item2 - 1]"/>
      </div>
    </div>
    <div class="news-more font-xbs" @click="showMore()" v-if="user.pages.sub.total - rownum * 3 > 0">
      展开更多
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import Newscard from "./Newscard.vue"
import { userinfo } from '@/stores/counter'
import getSubArticleList from '@/api/getSubArticleList'

const { subList } = getSubArticleList();
const user = userinfo()

const rownum = computed(() => {
  return Math.ceil(user.subArticleNum / 3)
})

function showMore() {
  user.pages.sub.page++;
  subList(user.pages.sub.cate);
}

const articleRowNum = (row: number) => {
  // console.log(user.subList)
  if (user.pages.sub.list.length == 0) return 0
  // return 3
  // console.log(row, user.subList.length - row * 3)
  return Math.min(3, user.pages.sub.list.length - row * 3)
}
</script>

<style scoped>
.news-arrow {
  margin-top: 30px;
}

.news-more {
  margin-top: 30px;
  color: #f59009;
  font-size: 24px;
  cursor: pointer;
}

.news-line {
  margin-top: 20px;
  height: 1px;
  background-color: #fbdcbe;
  width: 50%;
}

.newslist {
  padding: 30px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.card-section {
  width: 100%;
  max-width: 1920px;
  height: max-content;
  /* background-color: aqua; */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card-row {
  width: 100%;
  height: max-content;
  /* background-color: aqua; */
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}
</style>